import Vue from 'vue'
import VueRouter from 'vue-router'
import routerGuardInit from "@/common/router/routerGuard";
import routerExtendInit from "@/common/router/routerExtend";
import routes from "@/common/router/routes";

// 注入 路由
Vue.use(VueRouter)

// 重写 Push 规避缓存路由报错
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch(err => err)
}

// 实例化 路由
const router = new VueRouter({
    mode: 'hash',
    routes
})

// 初始化 路由守卫
routerGuardInit(router);

// 初始化 路由扩展
routerExtendInit(router, routes);

export default router
